export const validateIC = (rule,value,callback) =>{
  let IC=/^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
  if(value!="") {
    if (!IC.test(value)) {
      callback(new Error('身份证号码不合法！'))
    } else {
      callback()
    }
  }else{
    if(rule.required == true){
      callback(new Error('此为必填项请输入！'))
    } else {
      callback()
    }
  }
}

export const validatePostalCode = (rule, value, callback) => {
  let postCode=/^[1-9][0-9]{5}$/;
  if(value!="") {
    if (!postCode.test(value)) {
      callback(new Error('邮政编码不合法！'))
    } else {
      callback()
    }
  }else{
    if(rule.required == true){
      callback(new Error('此为必填项请输入！'))
    } else {
      callback()
    }
  }
}

export const validateTelephone = (rule, value, callback) => {
  let telPhone=/^((0\d{2,3}-\d{7,8})|(1[3584]\d{9}))$/;
  if(value!="") {
    if (!telPhone.test(value)) {
      callback(new Error('联系电话号码不合法！'))
    } else {
      callback()
    }
  }else{
    if(rule.required == true){
      callback(new Error('此为必填项请输入！'))
    } else {
      callback()
    }
  }
}

export const validateEmail = (rule, value, callback) => {
  let email=/^[a-z0-9A-Z]+[- | a-z0-9A-Z . _]+@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\.)+[a-z]{2,}$/;
  if(value!="") {
    if (!email.test(value)) {
      callback(new Error('电子邮箱不合法！'))
    } else {
      callback()
    }
  }else{
    if(rule.required == true){
      callback(new Error('此为必填项请输入！'))
    } else {
      callback()
    }
  }
}

export const validateIsQQ = (rule, value, callback) => {
  let isQQ=/^[1-9]\d{4,10}$/;
  if(value!="") {
    if (!isQQ.test(value)) {
      callback(new Error('QQ号码不合法！'))
    } else {
      callback()
    }
  }else{
    if(rule.required == true){
      callback(new Error('此为必填项请输入！'))
    } else {
      callback()
    }
  }
}

export const validateUnitFax = (rule, value, callback) => {
  let fax=/^(?:\d{3,4}-)?\d{7,8}(?:-\d{1,6})?$/;
  if(value!="") {
    if (!fax.test(value)) {
      callback(new Error('单位传真号码不合法！'))
    } else {
      callback()
    }
  }else{
    if(rule.required == true){
      callback(new Error('此为必填项请输入！'))
    } else {
      callback()
    }
  }
}

export const validateDigit = (rule, value, callback) => {
  let dig=/^[0-9]*$/;
  if(value!="") {
    if(!dig.test(value)){
      callback(new Error('只能输入数字！'))
    }else{
      callback()
    }
  }else{
    if(rule.required == true){
      callback(new Error('请上传课件！'))
    } else {
      callback()
    }
  }
}

export const validateDigitEnglish = (rule, value, callback) => {
  let digEn=/^[A-Za-z0-9]+$/;
  if(value!="") {
    if (!digEn.test(value)) {
      callback(new Error('只能输入数字和英文字母！'))
    } else {
      callback()
    }
  }else{
    if(rule.required == true){
      callback(new Error('此为必填项请输入！'))
    } else {
      callback()
    }
  }
}

export const validateDigitPoint = (rule, value, callback) => {
  let digPoint=/^(0|[1-9][0-9]*)(\.[0-9]{0,4})?$/;
  if(value!="") {
    if (!digPoint.test(value)) {
      callback(new Error('请输入数字且小数点后只能4位！'))
    } else {
      callback()
    }
  }else{
    if(rule.required == true){
      callback(new Error('此为必填项请输入！'))
    } else {
      callback()
    }
  }
}
